import json
import operator
# from comm.test_method import  RunMain
# from comm.get_data import  GetData
# from comm.operate_excel import  OperateExcel
# from comm.operate_json import  OperationJson
import pymysql
class Check():
    #3306数据库
    def coonect_db(self,database,sql,charset='utf8'):
        # self.conn=pymysql.connect(host="49.235.209.177",port=3306,user="devroot",passwd="devroot@123",db=database,charset='utf8')#115.159.76.132、49.235.209.177、10.105.201.137
        # self.conn = pymysql.connect(host="115.159.76.132", port=3306, user="devroot", passwd="devroot@123", db=database,charset='utf8')  #
        self.conn = pymysql.connect(host="10.21.32.3", port=3306, user="gordon", passwd="4qYAEZ6scVNYPLTWRviT",
                                    db=database, charset='utf8')
        self.cur=self.conn.cursor()
        try:
            self.cur.execute(sql)#执行sql语句
        except Exception as e:
            self.conn.rollback()# 事务回滚
            print("事务处理失败",e)
        else:
            self.conn.commit()#提交事务
            print('事务处理成功', self.cur.rowcount)
        results=self.cur.fetchall()
        return results



    #3307数据库
    def coonect_db_07(self, database, sql, charset='utf8'):
        # self.conn = pymysql.connect(host="49.235.209.177", port=3307, user="root", passwd="a6CFu3VH6OYW",
        #                             db=database, charset='utf8')  # 115.159.76.132
        # self.conn = pymysql.connect(host="115.159.76.132", port=3306, user="devroot", passwd="devroot@123", db=database,charset='utf8')  #
        self.conn = pymysql.connect(host="10.21.32.3", port=3306, user="gordon", passwd="4qYAEZ6scVNYPLTWRviT",
                                    db=database, charset='utf8')

        self.cur = self.conn.cursor()
        try:
            self.cur.execute(sql)#执行sql语句
        except Exception as e:
            self.conn.rollback()# 事务回滚
            print("事务处理失败",e)
        else:
            self.conn.commit()#提交事务
            print('事务处理成功', self.cur.rowcount)
        results=self.cur.fetchall()
        return results

     #判断返回结果是否包含预期结果
    def is_contain(self,str_one,str_two):#判断str_one是否包含于str_two
        flag=None
        try:
            str_one.index(str_two)>1
        except:
            print('PASS!')
            flag=False
        return flag



        def is_contain(self, str_one, str_two):  # 判断str_one是否包含于str_two
            flag = None
            try:
                str_one.index(str_two) > 1
            except:
                print('PASS!')
                flag = False
            return flag

     #判断两个字典是否相等
    def is_equal_dict(self,dict_one,dict_two):#判断两个字典值是否相等

        if isinstance(dict_one,dict_two):
            print('haha')
            dict_one =json.loads(dict_one)#str转成dict
            print(dict_two)
        else:
            print('oo')
        print(operator.eq(dict_one,dict_two))

if __name__=="__main__":
    C=Check()
    # sql = "select id from m_service_provider where username = '01240@gaopeng.com'"
    # value=C.coonect_db(database='fpmerchant', sql=sql, charset='utf8')
    # print (value)

    # id_num = C.coonect_db(database='fpmerchant', sql='select id from m_service_provider where username="17665280433"')[0]  # 获取服务商id
    # print(id_num)
    print(C.coonect_db_07(database="providers",sql="select * from gpi_order_invoice_201906 WHERE order_sn='gp_20190615141539_666_10838_35555'"))

    # print(C.coonect_db_07(database='providers',
    #                       sql="INSERT INTO gpi_tax_equipment (tax_code,client_id,tax_num,channel) VALUES ('GAPEN4a7rytl3ny','12471','kpyuan002','GP110003')"))
